<?php
class FileManipulator
{
   
   
   /**
	* read -- get data from file.
	*
	* @param    string    $filename    filename to read
	*
	* @return   string    data from file or false on failure
	* @access   public
	*/
	function read($filename) {

		$data = false;
		if($fp = @fopen($filename, "rb")) {
			$data = fread($fp, filesize($filename));
			fclose($fp);
		}
		return $data;
	}


   /**
	* write -- write data to file.
	*
	* @param    string    $filename    filename to write
	* @param    string    $data        data to write
	* 
	* @return   boolean   true/false
	* @access   public
	*/
	function write($filename, $data, $append = false) {	

		$ret = false;
		if($fp = @fopen($filename, 'ab')) {
			flock($fp, LOCK_EX);
			
			if($append == false) {
				ftruncate ($fp, 0);
			}
			
			fputs($fp, $data);
			fflush($fp);
			flock($fp, LOCK_UN);
			fclose($fp);
			$ret = true;
		}
		return $ret;
	}
}
?>
